package com.njlime.cms.service.app;

import com.njlime.cms.entities.InformationUp;
import com.njlime.cms.repository.app.AppInformationUpDao;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * Created by Dean on 2017/10/10.
 */
@Service
public class AppInformationUpService {
    @Resource
    AppInformationUpDao appInformationUpDao;
    @Resource
    AppInformationCommentService appInformationCommentService;


    /**
     * 判断当前information评论是否被点赞
     */
    public boolean isUped(Integer commentId, Integer userId) {
        int upCount = appInformationUpDao.userUpCount(commentId, userId);
        if (upCount > 0) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 点赞
     */
    @Transactional(readOnly = false)
    public void save(InformationUp info) {
        appInformationUpDao.save(info);
        appInformationCommentService.fabulousNumUpdate(info.getComment_id(), 1);
    }

    /**
     * 取消点赞
     */
    @Transactional(readOnly = false)
    public void del(Integer commentId, Integer userId) {
        appInformationUpDao.del(commentId, userId);
        appInformationCommentService.fabulousNumUpdate(commentId, -1);
    }

}

